package com.cy.pj.goods.controller;

import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    //一个方法可以对应多个URL,例：{"","",""}
    @RequestMapping({"/findById/{id}","/findById/","/findAll"})
    public String findByIdController(@PathVariable(required = false) Integer id, Model model){
        List<Goods> list=goodsService.findById(id);
        model.addAttribute("list", list);
        return "index";
    }
}
